package com.itheima.service.store.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.itheima.dao.store.QuestionItemDao;

import com.itheima.domain.store.QuestionItem;

import com.itheima.factory.DaoInstanceFactory;

import com.itheima.service.store.QuestionItemService;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.UUID;

public class QuestionItemServiceImpl implements QuestionItemService {
    @Override
    public PageInfo<QuestionItem> findAll( String questionId) {
        int page = 1;
        int size = 100;
        PageHelper.startPage(page, size);
        QuestionItemDao dao = DaoInstanceFactory.getMapper(QuestionItemDao.class);
        List<QuestionItem> list = dao.findAll(questionId);
        return new PageInfo<>(list);
    }



    @Override
    public void save(QuestionItem questionItem ) {
        QuestionItemDao dao = DaoInstanceFactory.getMapper(QuestionItemDao.class);
        String id = UUID.randomUUID().toString().replace("-", "");
        questionItem.setId(id);
        dao.save(questionItem);
    }

    @Override
    public QuestionItem findById(String id) {
        QuestionItemDao dao = DaoInstanceFactory.getMapper(QuestionItemDao.class);
        return dao.findById(id);

    }



    @Override
    public void update(QuestionItem questionItem) {
        QuestionItemDao dao = DaoInstanceFactory.getMapper(QuestionItemDao.class);
        dao.update(questionItem);
    }

    @Override
    public void delete(String id) {
        QuestionItemDao dao = DaoInstanceFactory.getMapper(QuestionItemDao.class);
        dao.delete(id);
    }
}
